package com.apes.scm.masterdata.party.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.scm.masterdata.party.model.Party;
import com.apes.scm.masterdata.party.model.Person;
import com.apes.scm.masterdata.product.model.Product;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface PersonRepository extends CustomRepository<Person, Long> {

    /***
     * 功能： 通过party 查询对应的人员信息
     * @param party
     * @return
     */

    Person findFirstByParty(Party party);

    @Query(value = "SELECT T FROM Person T WHERE  T.idCard = :idCard")
    Person findPersonIdCard(@Param("idCard") String idCard);

    @Query(value = "SELECT T FROM Person T WHERE T.mobileNumber = :mobileNumber")
    Person findPersonMobile(@Param("mobileNumber") String mobileNumber);

    List<Person> findByDingDingUserIdIsNotNull();

    @Query(value = "SELECT T FROM Person T WHERE  T.dingDingUserId = :userId")
    Person findByDingDingUserId(@Param("userId")String userId);

    @Query(value = "SELECT t.* from mas_person t WHERE t.party_id = (SELECT t.party_id FROM hr_employee t WHERE t.id = :employeeId)",nativeQuery = true)
    Person findByEmployeeId(@Param("employeeId")String employeeId);

}